﻿<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>倒计时限时特卖(原创)</title>
<script src="../js/jquery.min.js"></script>
<style>
#day,#hours,#minutes,#seconds {
	color:#f00;
	font-weight:bold;
}
</style>
</head>
<body>
<div class="countdown">
    <h2>倒计时(距离2029年5月19日23时)</h2>
    <p>
        <span id="day"></span> 天
        <span id="hours"></span> 时
        <span id="minutes"></span> 分
        <span id="seconds"></span> 秒
    </p>
</div>

<script>
var countDownTime = {
    init: function(a, b, c, d, e) {
        this.t = a, this.d = b, this.h = c, this.m = d, this.s = e
    },
    start: function() {
        var a = this;
        setInterval(a.timer, 1e3)
    },
    timer: function(a) {
        var b, c, d, e, f, g, h;
        a = this.countDownTime, b = new Date, c = new Date(a.t), d = c.getTime() - b.getTime(), e = Math.floor(a.formatTime(d, "day")), f = Math.floor(a.formatTime(d, "hours")), g = Math.floor(a.formatTime(d, "minutes")), h = Math.floor(a.formatTime(d, "seconds")), a.d && (a.d.innerText = a.formatNumber(e)), a.h && (a.h.innerText = a.formatNumber(f)), a.m && (a.m.innerText = a.formatNumber(g)), a.s && (a.s.innerText = a.formatNumber(h))
    },
    formatNumber: function(a) {
        if (a <= 0) {
            a = 0
        }
        return a = a.toString(), a[1] ? a : "0" + a
    },
    formatTime: function(a, b) {
        switch (b) {
            case "day":
                return a / 1e3 / 60 / 60 / 24;
            case "hours":
                return a / 1e3 / 60 / 60 % 24;
            case "minutes":
                return a / 1e3 / 60 % 60;
            case "seconds":
                return a / 1e3 % 60
        }
    }
};
$(function() {
    var day = document.getElementById('day');
    var hours = document.getElementById('hours');
    var minutes = document.getElementById('minutes');
    var seconds = document.getElementById('seconds');
    // 日 时 分 秒的dom对象
    countDownTime.init('2029/5/19 23:59:59', day, hours, minutes, seconds);
    countDownTime.start();
});
</script>

</body>
</html>
